package repository;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class FactoryConnection {

	private static FactoryConnection instance;
	private String url;
	private String usuario;
	private String senha;

	private FactoryConnection() {

		url = "jdbc:postgresql://127.0.0.1:5432/rdfilter";
		usuario = "postgres";
		senha = "a";

	}

	public static FactoryConnection getInstance() {

		if (instance == null)
			instance = new FactoryConnection();
		return instance;
	}

	/**
	 * Get a connection with Postgres database.
	 * 
	 * @return connection
	 * @throws ClassNotFoundException
	 *             invalid driver.
	 * @throws SQLException
	 *             invalid host.
	 */
	public Connection getConnection() throws ClassNotFoundException,
			SQLException {

		Class.forName("org.postgresql.Driver");
		Connection connection = DriverManager
				.getConnection(url, usuario, senha);

		return connection;
	}

}
